package pierwszy;

import org.openqa.selenium.NoSuchWindowException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;


public class LogInPage {
	
	private WebDriver driver;
	private WebDriverWait wait;
	
	public LogInPage(WebDriver driver, WebDriverWait wait){
		this.driver = driver;
		this.wait = wait;

		if (!driver.getTitle().equals("mAdmin- LOGOWANIE DO SYSTEMU")){
			throw new NoSuchWindowException("This is not the Login page");
		}
	}
	
	public MainPage logIn(String login, String password) {
        WebElement lgn = driver.findElement(UiMapping.LoginField);
        WebElement pswd = driver.findElement(UiMapping.PasswordField);
        WebElement lgnbtn = driver.findElement(UiMapping.LoginButton);
        
        lgn.sendKeys(login);
        pswd.sendKeys(password);
        lgnbtn.click();
        
        return new MainPage(driver, wait);
	}
}
